import Api from "../experience/api/Api.js";
import Drawer from "../experience/drawer/Drawer.js";
import Utils from "../experience/utils/Utils.js";
import Algorithm from "../experience/utils/Algorithm.js";

import MineFilter from "../component/piece/MineFilter.js";
import Uploader from "../component/piece/Uploader.js";
import Editor from "../component/piece/Editor.js";
import Layer from "../component/piece/Layer.js";
import Tree from "../component/piece/Tree.js";

const $$ = Dom7;

class Urd {
    static instance;

    constructor() {
        if (Urd.instance) {
            return Urd.instance;
        }
        Urd.instance = this;

        this.api = new Api();
        this.utils = new Utils();
        this.algo = new Algorithm();
        this.drawer = new Drawer();

        this.init().then(() => {
            console.log("Walküre Fly...");
        });

        new MineFilter();
        new Uploader();
        new Editor();
        new Layer();
        new Tree();
    }

    // 全局初始化
    async init() {
        // 获取配置用的code信息
        const data = await this.api.getCode()
        this.utils.setLocalStorage('code', data.data);

        const mine = {
            code: "130204002082",
            name: "开滦能源化工股份有限公司范各庄矿业分公司",
            address: "河北省唐山市古冶区南范各庄镇",
            longitude: 118.262,
            latitude: 39.3838
        }
        this.utils.setLocalStorage("mine", mine);

        // 从本地获取数据
        if (this.algo.getConfig() !== null) {
            await this.drawer.location();
        }

        // 全局pannel关闭
        $$("#pannel-close").on("click", () => {
            $$("#pannel").hide()
        })
    }
}

new Urd();